############################################################
# The CMakeLists.txt for the ETF's G4 simulation project
# Created: Sun Yazhou, Nov. 6, 2023
# Last modified: Sun Yazhou, Nov.6, 2023
#
# \copyright Copyright (c) 2023-2024 IMP-CAS with LGPLv3 LICENSE
#############################################################

cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

# use clang if possible
find_program(CLANG_EXECUTABLE clang++)
if(CLANG_EXECUTABLE)
  set(CMAKE_CXX_COMPILER "clang++")
  set(CMAKE_C_COMPILER "clang")
endif()

project(EG4)

set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules")
# Build Type: MinSizeRel Debug Release RelWithDebInfo
# set(BUILD_TYPE Debug) # appropriate for DEBUG, yet rather slow
set(BUILD_TYPE Release) # compiler-optimized, extreme performance
# set(BUILD_TYPE MinSizeRel) # rel, and with minized lib and exe size
# set(BUILD_TYPE RelWithDebInfo) # rel, and with DEB info
if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE ${BUILD_TYPE})
else()
  set(BUILD_TYPE ${CMAKE_BUILD_TYPE})
endif()

find_package(Geant4 REQUIRED ui_all vis_all)
message(STATUS ${GEANT4_CXX_FLAGS})
find_package(ROOT REQUIRED)
include(EG4Macros)

add_subdirectory(sim)
add_subdirectory(src)

file(COPY ${PROJECT_SOURCE_DIR}/config/run.mac DESTINATION ${PROJECT_BINARY_DIR})
file(COPY ${PROJECT_SOURCE_DIR}/config/batch.mac DESTINATION ${PROJECT_BINARY_DIR})
file(COPY ${PROJECT_SOURCE_DIR}/config/a.sh DESTINATION ${PROJECT_BINARY_DIR})
file(COPY ${PROJECT_SOURCE_DIR}/config/rootlogon.C DESTINATION ${PROJECT_BINARY_DIR})

# print the build type
string(TOUPPER ${BUILD_TYPE} BUILD_TYPE_UPPER)
execute_process(
  COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
  OUTPUT_VARIABLE COMPILER_VERSION
)
string(STRIP ${COMPILER_VERSION} COMPILER_VERSION_STRIPPED)
message(STATUS "======= BUILD TYPE ===========")
message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER} ${COMPILER_VERSION_STRIPPED}")
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}   ${CMAKE_CXX_FLAGS_${BUILD_TYPE_UPPER}}")
message(STATUS "(TIPS: Change with -DCMAKE_BUILD_TYPE=<build_type>)")
message(STATUS "(TIPS: Available build_type-s: MinSizeRel Debug Release RelWithDebInfo)")
message(STATUS "======= BUILD TYPE ===========")
